<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
	<ui:composition template="/templates/padraoJSF.xhtml">
		<ui:define name="barraTitulo">Matr&iacute;cula do Aluno</ui:define>
		<ui:define name="conteudo">
			<p:dialog header="Pesquisas" width="600" height="500" widgetVar="modalPsq" modal="true" onCloseUpdate="form" fixedCenter="true" effect="FADE">
				<h:form id="formPesquisa">
					<p:tabView id="tabView">
						<p:tab title="Pesquisa de Aluno">
							<fieldset>
								<h:panelGrid columns="2" columnClasses="alinhaEsq width50">
									<h:column>
										<h:outputText value="Nome:" styleClass="textfield" />
									</h:column>
									<h:column>
										<h:inputText value="#{controleMatricula.pesquisaNome}" size="75" styleClass="textfield" />
									</h:column>								
								</h:panelGrid>
							</fieldset>
						</p:tab>
					</p:tabView>
					<p:commandLink action="#{controleMatricula.pesquisaAlunoNome}" styleClass="alinhaDir" update=":formPesquisaResultado">
						<h:graphicImage url="/images/botoes/btnPesquisar.png" class="btnAcoes"/>
					</p:commandLink>
					<br/>
					<br/>
				</h:form>
				<h:form id="formPesquisaResultado">
					<p:dataTable value="#{controleMatricula.lista}" 
					             id="id_ListaAluno"
					             var="aluno" 
					             paginator="true" 
					             rows="10" 
					             dynamic="true" 
					             rendered="#{not empty controleMatricula.lista}" 
								 firstPageLinkLabel="Primeiro"
					             previousPageLinkLabel="Anterior"
					             nextPageLinkLabel ="Pr&oacute;ximo"
					             lastPageLinkLabel="&Uacute;ltima"
					             emptyMessage="Nenhum resgistro encontrado"
					             errorMessage="Ocorreu um erro"
	    			             selection="#{controleMatricula.aluno}" 
					             selectionMode="single" >
						<p:column styleClass="width60"  >
							<f:facet name="header">
								<h:outputText value="Matr&iacute;cula" />
							</f:facet>
							<h:outputText value="#{aluno.matricula}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Nome" />
							</f:facet>
							<h:outputText value="#{aluno.pessoa.nome}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="CPF" />
							</f:facet>
							<h:outputText value="#{aluno.pessoa.CPF}">
								<f:converter converterId="converteCPF" />
							</h:outputText>
						</p:column>
						<p:column resizable="true" styleClass="width80">
							<f:facet name="header">
								<h:outputText value="A&ccedil;&atilde;o" /> 
							</f:facet>
                               <h:commandLink action="matricula">  
                                    <p:graphicImage url="/images/marcadores/editar.png" alt="Seleciona Aluno"/>  
                                    <f:setPropertyActionListener target="#{controleMatricula.aluno}" value="#{aluno}" />
                               </h:commandLink>
                     	</p:column>						
					</p:dataTable>
				</h:form>
			</p:dialog>		
			<h:form id="form">
				<p:growl id="messages"/>
				<fieldset>
					<p:panel header="Dados do Aluno">
						<br></br>				
						<h:panelGrid columns="2" columnClasses="alinhaDir">			
							<h:column>
								<h:outputText value="Matr&iacute;cula:"/>
							</h:column>
							<h:column>
								<h:inputText id="pesquisaMatricula" rendered="#{empty controleMatricula.aluno.matricula}" size="15" maxlength="15" value="#{controleMatricula.pesquisaMatricula}" styleClass="upper" >
									<f:ajax update="form" event="blur" listener="#{controleMatricula.pesquisaAlunoMatricula}" />
								</h:inputText>
								<h:inputText id="matricula" rendered="#{not empty controleMatricula.aluno.matricula}" size="15" maxlength="15" value="#{controleMatricula.aluno.matricula}" styleClass="upper" >
									<f:ajax update="form" event="blur" listener="#{controleMatricula.pesquisaAlunoMatricula}" />
								</h:inputText>
								<h:outputLink value="#">
									<h:graphicImage url="/images/botoes/btnPesquisar.png" onclick="modalPsq.show();" styleClass="iconesLaterais" />
								</h:outputLink>
							</h:column>		
							<h:column>
								<h:outputText value="Nome:" styleClass="textfield" />
							</h:column>
							<h:column>
								<h:outputText value="#{controleMatricula.aluno.pessoa.nome}" styleClass="textfield" />
							</h:column>
							<h:column>
								<h:outputText value="Curso:" styleClass="textfield" />
							</h:column>
							<h:column>
								<h:outputText value="#{controleMatricula.aluno.curso.descricao}" styleClass="textfield" />
							</h:column>
							<h:column>
								<h:outputText value="Grade Curricular:" styleClass="textfield" />
							</h:column>
							<h:column>
								<h:outputText value="#{controleMatricula.aluno.gradeCurricular.descricao}" styleClass="textfield" />
							</h:column>
						</h:panelGrid>
					</p:panel>
				</fieldset>
				<c:if test="#{controleMatricula.aluno.statusAluno.codigoStatus != 1}" >
					<fieldset>
						<h:panelGrid columns="2" columnClasses="alinhaEsq">
							<h:column>
								<h:outputLabel value="#{controleMatricula.aluno.gradeCurricular.turmas[0].descricao}" />
								<p:accordionPanel autoHeight="false">
									<c:forEach var="itemTurma" items="#{controleMatricula.aluno.gradeCurricular.turmas}">
										<p:tab title="TESTE">a</p:tab>
									</c:forEach>
								</p:accordionPanel>
								<p:accordionPanel id="periodos">
									<c:forEach var="itemTurma" items="#{controleMatricula.aluno.gradeCurricular.turmas}">
										<c:forEach var="turmaOferta" items="#{itemTurma.turmaOferta}">						
											<p:tab title="#{itemTurma.periodo}&deg; per&iacute;odo">
												<ui:repeat var="turmaOfertaDisciplina" value="#{turmaOferta.turmaOfertaDisciplina}">
													<fieldset>
														<h:panelGrid columns="1" styleClass="titulo alinhaEsq" >
															<h:column>
															    <h:outputText value="DISCIPLINA:" styleClass="creditos" />
																<h:outputText value="#{turmaOfertaDisciplina.disciplina.codigoDisciplina}"/>&nbsp;-&nbsp;
																<h:outputText value="#{turmaOfertaDisciplina.disciplina.descricao}"/>
															</h:column>
														</h:panelGrid>
														<h:panelGrid columns="6" styleClass="titulo alinhaEsq">
															<h:column>
																<h:outputText value="CR&Eacute;DITOS:" styleClass="creditos" />
																<h:outputText value="#{turmaOfertaDisciplina.disciplina.creditos}"/>
															</h:column>
															<h:column>
																<h:outputText value="TURMA: " styleClass="creditos"/>
																<h:outputText value="#{itemTurma.descricao}" styleClass="turma"/>&nbsp;&nbsp;&nbsp;
															</h:column>
															<h:column>
																<h:outputText value="TURNO: " styleClass="creditos"/>
																<h:outputText value="#{itemTurma.turno}" styleClass="turma"/>
															</h:column>
															<h:column />
															<h:column />
															<h:column>
																<p:commandLink action="#{controleMatricula.adicionaDisciplina}" styleClass="alinhaDir" update=":form">
																	<h:graphicImage url="/images/marcadores/add.png"/>&nbsp;
																	<f:setPropertyActionListener target="#{controleMatricula.turmaOfertaDisciplina}" value="#{turmaOfertaDisciplina}" />
																	<h:outputText value="Incluir "/>&nbsp;
																</p:commandLink>&nbsp;
																<p:commandLink action="#{controleMatricula.removeDisciplina}" styleClass="alinhaDir" update=":form">
																	<h:graphicImage url="/images/marcadores/remove.png"/>&nbsp;
																	<f:setPropertyActionListener target="#{controleMatricula.turmaOfertaDisciplina}" value="#{turmaOfertaDisciplina}" />
																	<h:outputText value="excluir "/>&nbsp;
																</p:commandLink>&nbsp;
															</h:column>
														</h:panelGrid>											
														<table>
															<tr class="titulo">
																<c:if test="${corTabela != 'corUm'}" var="controleCor">
																	<c:set var="corTabela" value="corUm"></c:set>
																</c:if>
																<c:if test="${corTabela != 'corDois' and controleCor == false}">
																	<c:set var="corTabela" value="corDois"></c:set>
																</c:if>
																<c:if test="#{controleMatricula.tipoCurso.codigoTipoCurso == 1}" >
																	<c:forEach var="dia" begin="1" end="7" step="1">
																		<td class="width30 alinhaMeio">#{controleMatricula.dias[dia]}</td>
																	</c:forEach>
																</c:if>
															</tr>
															<c:if test="#{controleMatricula.tipoCurso.codigoTipoCurso == 1}" >
																<tr class="corDois">
																	<c:forEach var="dia" begin="1" end="7" step="1">
																		<td class="width30 alinhaMeio">
																			<ui:repeat var="horario" value="${turmaOfertaDisciplina.horarios}">
																				<c:choose>
																					<c:when test="${horario.dia == dia}">
																						<h:outputText value="#{horario.aula}&ordf;"/>&nbsp;&nbsp;
																					</c:when>
																				</c:choose>
																			</ui:repeat>
																		</td>
																	</c:forEach>
																</tr>
															</c:if>
														</table>
													</fieldset>														
												</ui:repeat>
											</p:tab>
										</c:forEach>
									</c:forEach>
								</p:accordionPanel>
							</h:column>							
						</h:panelGrid>
					</fieldset>
				</c:if>
				<c:if test="#{controleMatricula.aluno.statusAluno.codigoStatus == 1}" >
					<fieldset> 
						<h:panelGrid columns="2" columnClasses="alinhaEsq">
							<h:column>
								<p:accordionPanel id="periodos" activeIndex="0">

									<p:tab title="Disciplinas Matriculada">
										<ui:repeat var="turmaOfertaDisciplina" value="#{controleMatricula.aluno.turmaOfertaDisciplinas}">
											<fieldset>
												<h:panelGrid columns="1" styleClass="titulo alinhaEsq" >
													<h:column>
													    <h:outputText value="DISCIPLINA:" styleClass="creditos" />
														<h:outputText value="#{turmaOfertaDisciplina.disciplina.codigoDisciplina}"/>&nbsp;-&nbsp;
														<h:outputText value="#{turmaOfertaDisciplina.disciplina.descricao}"/>
													</h:column>
												</h:panelGrid>
												<h:panelGrid columns="6" styleClass="titulo alinhaEsq">
													<h:column>
														<h:outputText value="CR&Eacute;DITOS:" styleClass="creditos" />
														<h:outputText value="#{turmaOfertaDisciplina.disciplina.creditos}"/>
													</h:column>
													<h:column>
														<h:outputText value="TURMA: " styleClass="creditos"/>
														<h:outputText value="#{turmaOfertaDisciplina.turmaOferta.turma.descricao}" styleClass="turma"/>&nbsp;&nbsp;&nbsp;
													</h:column>
													<h:column>
														<h:outputText value="TURNO: " styleClass="creditos"/>
														<h:outputText value="#{turmaOfertaDisciplina.turmaOferta.turma.turno}" styleClass="turma"/>
													</h:column>
													<h:column />
													<h:column />
												</h:panelGrid>											
												<table>
													<tr class="titulo">
														<c:if test="${corTabela != 'corUm'}" var="controleCor">
															<c:set var="corTabela" value="corUm"></c:set>
														</c:if>
														<c:if test="${corTabela != 'corDois' and controleCor == false}">
															<c:set var="corTabela" value="corDois"></c:set>
														</c:if>
														<c:if test="#{controleMatricula.tipoCurso.codigoTipoCurso == 1}" >
															<c:forEach var="dia" begin="1" end="7" step="1">
																<td class="width30 alinhaMeio">#{controleMatricula.dias[dia]}</td>
															</c:forEach>
														</c:if>
													</tr>
													<c:if test="#{controleMatricula.tipoCurso.codigoTipoCurso == 1}" >
														<tr class="corDois">
															<c:forEach var="dia" begin="1" end="7" step="1">
																<td class="width30 alinhaMeio">
																	<ui:repeat var="horario" value="${turmaOfertaDisciplina.horarios}">
																		<h:outputText value="#{horario.aula}&ordf;" rendered="${horario.dia == dia}"/>&nbsp;&nbsp;
																	</ui:repeat>
																</td>
															</c:forEach>
														</tr>
													</c:if>
												</table>
											</fieldset>									
										</ui:repeat>
									</p:tab>
								</p:accordionPanel>
							</h:column>					
						</h:panelGrid>
					</fieldset>
				</c:if>
				<c:if test="#{controleMatricula.tipoCurso.codigoTipoCurso == 1}" >
					<fieldset>
						<table id="tabelaManha">
						 	<tr>
								<td class="width100 alinhaMeio turno">Manh&atilde;</td>
								<td>
									<table>
										<tr class="titulo">
											<td class="width70 alinhaMeio"><span class="alinhaMeio"><strong>aula</strong></span></td>
											<td class="alinhaMeio width100"><strong>Seg</strong></td>
											<td class="alinhaMeio width100"><strong>Ter</strong></td>
											<td class="alinhaMeio width100"><strong>Qua</strong></td>
											<td class="alinhaMeio width100"><strong>Qui</strong></td>
											<td class="alinhaMeio width100"><strong>Sex</strong></td>
											<td class="alinhaMeio width100"><strong>Sab</strong></td>
											<td class="alinhaMeio width100"><strong>Dom</strong></td>
										</tr>
										<c:forEach var="aula" begin="1" end="5" step="1">
											<c:if test="${corTabela != 'corUm'}" var="controleCor">
												<c:set var="corTabela" value="corUm"></c:set>
											</c:if>
											<c:if test="${corTabela != 'corDois' and controleCor == false}">
												<c:set var="corTabela" value="corDois"></c:set>
											</c:if>
											<tr class="${corTabela}">
												<td class="alinhaMeio">#{aula}&ordf;</td>
												<c:forEach var="dia" begin="1" end="7" step="1">
													<td class="alinhaMeio">
														<ui:repeat var="turmaOfertaDisciplina" value="#{controleMatricula.aluno.turmaOfertaDisciplinas}">
															<ui:repeat var="horarioM" value="#{turmaOfertaDisciplina.horarios}">
																<h:outputText value="#{turmaOfertaDisciplina.disciplina.codigoDisciplina}" title="#{turmaOfertaDisciplina.disciplina.descricao}" rendered="#{horarioM.dia == dia and horarioM.aula == aula and turmaOfertaDisciplina.turmaOferta.turma.turno == 'M' }"/>
															</ui:repeat>
														</ui:repeat>
													</td>
												</c:forEach>
											</tr>
										</c:forEach>										
									</table>
								</td>
							</tr>
						</table>
					</fieldset>
					<fieldset>
						<table  id="tabelaTarde">
						 	<tr>
								<td class="width100 alinhaMeio turno">Tarde</td>
								<td>
									<table>
										<tr class="titulo">
											<td class="width70 alinhaMeio"><span class="alinhaMeio"><strong>aula</strong></span></td>
											<td class="alinhaMeio width100"><strong>Seg</strong></td>
											<td class="alinhaMeio width100"><strong>Ter</strong></td>
											<td class="alinhaMeio width100"><strong>Qua</strong></td>
											<td class="alinhaMeio width100"><strong>Qui</strong></td>
											<td class="alinhaMeio width100"><strong>Sex</strong></td>
											<td class="alinhaMeio width100"><strong>Sab</strong></td>
											<td class="alinhaMeio width100"><strong>Dom</strong></td>
										</tr>
										<c:forEach var="aula" begin="1" end="5" step="1">
											<c:if test="${corTabela != 'corUm'}" var="controleCor">
												<c:set var="corTabela" value="corUm"></c:set>
											</c:if>
											<c:if test="${corTabela != 'corDois' and controleCor == false}">
												<c:set var="corTabela" value="corDois"></c:set>
											</c:if>
											<tr class="${corTabela}">
												<td class="alinhaMeio">#{aula}&ordf;</td>
												<c:forEach var="dia" begin="1" end="7" step="1">
													<td class="alinhaMeio">
														<ui:repeat var="turmaOfertaDisciplina" value="#{controleMatricula.aluno.turmaOfertaDisciplinas}">
															<ui:repeat var="horarioM" value="#{turmaOfertaDisciplina.horarios}">
																<h:outputText value="#{turmaOfertaDisciplina.disciplina.codigoDisciplina}" title="#{turmaOfertaDisciplina.disciplina.descricao}" rendered="#{horarioM.dia == dia and horarioM.aula == aula and turmaOfertaDisciplina.turmaOferta.turma.turno == 'V' }"/>
															</ui:repeat>
														</ui:repeat>
													</td>
												</c:forEach>
											</tr>
										</c:forEach>										
									</table>
								</td>
							</tr>
						</table>
					</fieldset>		
					<fieldset>
						<table id="tabelaNoite">
						 	<tr>
								<td class="width100 alinhaMeio turno">Noite</td>
								<td>
									<table>
										<tr class="titulo">
											<td class="width70 alinhaMeio"><span class="alinhaMeio"><strong>aula</strong></span></td>
											<td class="alinhaMeio width100"><strong>Seg</strong></td>
											<td class="alinhaMeio width100"><strong>Ter</strong></td>
											<td class="alinhaMeio width100"><strong>Qua</strong></td>
											<td class="alinhaMeio width100"><strong>Qui</strong></td>
											<td class="alinhaMeio width100"><strong>Sex</strong></td>
											<td class="alinhaMeio width100"><strong>Sab</strong></td>
											<td class="alinhaMeio width100"><strong>Dom</strong></td>
										</tr>
										<c:forEach var="aula" begin="1" end="5" step="1">
											<c:if test="${corTabela != 'corUm'}" var="controleCor">
												<c:set var="corTabela" value="corUm"></c:set>
											</c:if>
											<c:if test="${corTabela != 'corDois' and controleCor == false}">
												<c:set var="corTabela" value="corDois"></c:set>
											</c:if>
											<tr class="${corTabela}">
												<td class="alinhaMeio">#{aula}&ordf;</td>
												<c:forEach var="dia" begin="1" end="7" step="1">
													<td class="alinhaMeio">
														<ui:repeat var="turmaOfertaDisciplina" value="#{controleMatricula.aluno.turmaOfertaDisciplinas}">
															<ui:repeat var="horarioM" value="#{turmaOfertaDisciplina.horarios}">
																<h:outputText value="#{turmaOfertaDisciplina.disciplina.codigoDisciplina}" title="#{turmaOfertaDisciplina.disciplina.descricao}" rendered="#{horarioM.dia == dia and horarioM.aula == aula and turmaOfertaDisciplina.turmaOferta.turma.turno == 'N' }"/>
															</ui:repeat>
														</ui:repeat>
													</td>
												</c:forEach>
											</tr>
										</c:forEach>										
									</table>
								</td>
							</tr>
						</table>
					</fieldset>
				</c:if>		
				<c:if test="#{controleMatricula.aluno != null}" >
					<c:if test="#{controleMatricula.tipoCurso.codigoTipoCurso == 2}" >
						<c:if test="#{controleMatricula.aluno.statusAluno.codigoStatus != 1}" >
							<fieldset> 
								<h:panelGrid columns="2" columnClasses="alinhaEsq">
									<h:column>
										<p:accordionPanel id="periodosPos" activeIndex="0">
											<p:tab title="Disciplinas Matriculada">
												<ui:repeat var="turmaOfertaDisciplina" value="#{controleMatricula.aluno.turmaOfertaDisciplinas}">
													<fieldset>
														<h:panelGrid columns="1" styleClass="titulo alinhaEsq" >
															<h:column>
															    <h:outputText value="DISCIPLINA:" styleClass="creditos" />
																<h:outputText value="#{turmaOfertaDisciplina.disciplina.codigoDisciplina}"/>&nbsp;-&nbsp;
																<h:outputText value="#{turmaOfertaDisciplina.disciplina.descricao}"/>
															</h:column>
														</h:panelGrid>
														<h:panelGrid columns="6" styleClass="titulo alinhaEsq">
															<h:column>
																<h:outputText value="CR&Eacute;DITOS:" styleClass="creditos" />
																<h:outputText value="#{turmaOfertaDisciplina.disciplina.creditos}"/>
															</h:column>
															<h:column>
																<h:outputText value="TURMA: " styleClass="creditos"/>
																<h:outputText value="#{turmaOfertaDisciplina.turmaOferta.turma.descricao}" styleClass="turma"/>&nbsp;&nbsp;&nbsp;
															</h:column>
															<h:column>
																<h:outputText value="TURNO: " styleClass="creditos"/>
																<h:outputText value="#{turmaOfertaDisciplina.turmaOferta.turma.turno}" styleClass="turma"/>
															</h:column>
															<h:column />
															<h:column />
														</h:panelGrid>											
														<table>
															<tr class="titulo">
																<c:if test="${corTabela != 'corUm'}" var="controleCor">
																	<c:set var="corTabela" value="corUm"></c:set>
																</c:if>
																<c:if test="${corTabela != 'corDois' and controleCor == false}">
																	<c:set var="corTabela" value="corDois"></c:set>
																</c:if>
															</tr>
														</table>
													</fieldset>
												</ui:repeat>
											</p:tab>
										</p:accordionPanel>
									</h:column>						
								</h:panelGrid>
							</fieldset>
						</c:if>
					</c:if>
				</c:if>
				<h:commandLink action="#{controleMatricula.matricular}" styleClass="alinhaDir">
					<f:setPropertyActionListener target="#{controleMatricula.tipoMatricula}" value="1"/>
					<h:graphicImage url="/images/botoes/btnGravar.png" class="btnAcoes"/>
				</h:commandLink>					
			</h:form>
		</ui:define>
	</ui:composition>
</html>